package com.zretc.service.impl;

import com.zretc.dao.CommentMapper;
import com.zretc.dao.SalesMapper;
import com.zretc.entity.Sales;
import com.zretc.service.ComSaleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class ComSaleServiceImpl implements ComSaleService {

    @Autowired
    private SalesMapper salesMapper;

    @Autowired
    private CommentMapper commentMapper;

    /**
     * 顾客数量
     * @param sellerAccount
     * @return
     */
    @Override
    public Integer getCountSalesBySellerAccount(String sellerAccount) {
        return salesMapper.getCountSales(sellerAccount);
    }

    /**
     * 评论数量
     * @param sellerAccount
     * @return
     */
    @Override
    public Integer getCountCommentBySellerAccount(String sellerAccount) {
        return commentMapper.getCountComment(sellerAccount);
    }

    @Override
    public List<Map<String, Object>> getSalesBySellerAccount(Map<String,Object> param) {
        if ("".equals(param.get("salesDate")) || param.get("salesDate") == null) {
            param.put("salesDate", null);
        }else {
            param.put("salesDate", param.get("salesDate"));
            param.put("groupBy","groupBy");
        }
        if ("".equals(param.get("salesDateYear")) || param.get("salesDateYear") == null) {
            param.put("salesDateYear", null);
        }else {
            param.put("salesDateYear", param.get("salesDateYear"));
        }
        if ("".equals(param.get("salesDateBet")) || param.get("salesDateBet") == null) {
            param.put("salesDateBet", null);
        }else {
            param.put("salesDateBet", param.get("salesDateBet"));
        }
        if ("".equals(param.get("salesDateBetween")) || param.get("salesDateBetween") == null) {
            param.put("salesDateBetween", null);
        }else {
            param.put("salesDateBetween", param.get("salesDateBetween"));
        }
        return salesMapper.getSales(param);
    }
}
